cc.Class({
    extends: cc.Component,

    properties: {
        ownAchievement: cc.Label,    //成就
        ownRank: cc.Label,           //排名
        ownName: cc.Label,           //姓名
        ownScore: cc.Label,          //得分
        ownHead: cc.Sprite,          //头像
    },

    /**
     * 将个人信息打印到UI
     */
    property: function (data) {
        if (data) {

            this.ownRank.string = data.rank;
            this.ownName.string = data.name;
            this.ownScore.string = data.score;

            // 当显示自己的排名，显示"me"图标
            if (window.myOpenid != data.openid) {
                this.node.getChildByName("rankFrame_03").getChildByName("me").active = false;
            }

            //前三名显示奖牌
            if (data.rank < 4) {
                this.ownAchievement.string = data.rank;
                this.ownRank.node.active = false;  //隐藏名次文本
            } else {
                //隐藏除了前三名之外的个人排名信息节点下用来显示前三名奖牌的文本组件
                this.ownAchievement.node.active = false;
            }

            //显示头像
            if (data.url) {
                let url = data.url;
                let self = this;
                cc.loader.load({ url: url, type: 'png' }, function (err, img) {
                    if (err) return;
                    let myHead = new cc.SpriteFrame(img);
                    self.ownHead.spriteFrame = myHead;
                    self.ownHead.node.width = 63;
                    self.ownHead.node.height = 60;
                })
            }

            //如果玩家名字大于10个字就取前8个字加...
            let str = this.ownName.string;
            if (str.length > 10) {
                this.ownName.string = str.substring(0, 8) + "...";
            }

        }
    },

});
